package cn.swust.designpatternlearningplatform.domain.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.BeanUtils;

import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class TopicDto {
    private Integer topicId;
    /**
     * 知识点
     */
    private List<KnowledgePointDto> points;
    /**
     * 题目类型，多选，单选，判断
     * 1为单选
     * 2为多选
     * 3为判断
     */
    private String topicType;
    /**
     * 题目内容
     */
    private String topicContent;
    /**
     * 题目类容的图片路径
     */
    private String topicContentPath;
    /**
     * 答案
     */
    private String topicAnswer;
    /**
     * 题目解析
     */
    private String topicAnalyse;
    /**
     * 题目解析的图片路径
     */
    private String topicAnalysePath;
    /**
     * 题目难度
     * 1为简单
     * 2为普通
     * 3为困呐
     */
    private String topicDifficulty;
    /**
     * 是否收藏
     **/
    private Boolean isCollect;
    /**
     * 是否收藏
     **/
    private Boolean isShield;
    /**
     * 题目选项
     **/
    private List<TopicOptionDto> topicOptionDtos;

    public void setTopicOptionDtos(List<TopicOptionDto> topicOptionDtos) {
        topicOptionDtos.sort(Comparator.comparing(TopicOptionDto::getOptionName));
        this.topicOptionDtos = topicOptionDtos;
    }

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Timestamp problemTime;

    public static @NotNull TopicDto clone(TopicDto topicDto) {
        TopicDto topicDto1 = new TopicDto();
        BeanUtils.copyProperties(topicDto, topicDto1);
        return topicDto1;
    }
}
